package cn.hr.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import cn.hr.utils.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import cn.hr.dao.mapper.DictionaryMapper;
import cn.hr.pojo.Dictionary;
import cn.hr.service.DictionaryService;

/**
 * 数据字典服务接口实现类
 *
 * @author MO
 */
@CacheConfig(cacheNames = "dictionary")
@Scope("prototype")
@Service("dictionaryService")
public class DictionaryServiceImpl implements DictionaryService {
    @Resource
    private DictionaryMapper dictionaryMapper;

    @Override
    public boolean insert(Dictionary t) throws Exception {
        return dictionaryMapper.insert(t)>0;
    }

    @Override
    public boolean update(Dictionary t) throws Exception {
        return dictionaryMapper.update(t)>0;
    }

    @Override
    public boolean delete(Integer id) throws Exception {
        return dictionaryMapper.delete(id)>0;
    }

    @Override
    public Dictionary get(Integer id) throws Exception {
        return dictionaryMapper.get(id);
    }

    @Override
    public PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception {
        PageHelper.startPage(pageNo, Constants.PAGESIZE);
        List<Map> list = dictionaryMapper.findListByCondition(m);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Long findCountByCondition(Map m) throws Exception {
        return null;
    }


    @Override
    public List<Dictionary> selectAllByTypeName(String typeName) throws SQLException{
        return dictionaryMapper.selectAllByTypeName(typeName);
    }

    @Override
    public Dictionary get(String type, Integer val) throws SQLException{
        return dictionaryMapper.getByType(type,val);
    }

}
